package com.zone.domain.acticity.service.armory.impl;

import com.zone.domain.acticity.model.entity.ActivitySkuEntity;
import com.zone.domain.acticity.repository.IActivityRepository;
import com.zone.domain.acticity.service.ActivitySupport;
import com.zone.domain.acticity.service.armory.IActivitySkuArmory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: zongzi
 * @description: 活动库存兵工厂实现类
 * @date: 2025/2/15
 */
@Slf4j
@Service
public class ActivitySkuArmoryImpl implements IActivitySkuArmory {
    @Autowired
    private ActivitySupport activityOrderSupport;
    @Autowired
    private IActivityRepository activityRepository;

    @Override
    public void assembleActivitySkuStockCountByActivity(Long activityId) {
        List<ActivitySkuEntity> activitySkuEntities = activityRepository.queryActivitySkuList(activityId);
        activitySkuEntities.forEach(activitySkuEntity -> {
            activityRepository.assembleSkuStock(activitySkuEntity.getSku(), activitySkuEntity.getStockCount());
        });
    }

    @Override
    public void assembleActivitySkuStockCount(Long sku) {
        ActivitySkuEntity activitySkuEntity = activityOrderSupport.queryActivitySku(sku);
        // 装配活动库存数量
        activityRepository.assembleSkuStock(sku, activitySkuEntity.getStockCount());
    }
}
